﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.NeighborUI {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.sim.*;
    import Display.*;
    import flash.text.*;
    import Display.aswingui.*;
    import Display.PopulationUI.*;
    import Engine.*;
    import L10n.*;

    public class CityNamePanel extends JPanel implements IPopulationStateObserver {

        protected var m_nameText:JTextField;
        private var m_bigForm:TextFormat;
        private var m_popNumber:JLabel;
        private var m_bMade:Boolean = false;
        private var popTimer:Timer;

        public function CityNamePanel(_arg1:LayoutManager=null){
            this.popTimer = new Timer(1000);
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.TOP));
            Global.world.citySim.addObserver(this);
            this.init();
            this.addEventListener(MouseEvent.ROLL_OVER, this.onMouseOver, false, 0, true);
            this.addEventListener(MouseEvent.ROLL_OUT, this.onMouseOut, false, 0, true);
        }
        protected function init():void{
            this.mouseChildren = false;
            this.setBackgroundDecorator(new MarginBackground((new EmbeddedArt.nghbr_pop_65() as DisplayObject), new Insets(6, 20)));
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel();
            var _local2:TextFormat = new TextFormat();
            _local2.align = TextFormatAlign.CENTER;
            this.m_bigForm = new TextFormat();
            this.m_bigForm.size = 20;
            this.m_bigForm.align = TextFormatAlign.CENTER;
            var _local3:String = Global.player.cityName;
            if (TextFieldUtil.isLowerCase(_local3)){
                _local3 = _local3.toUpperCase();
            };
            this.m_nameText = ASwingHelper.makeTextField(_local3, EmbeddedArt.TITLE_FONT, 13, EmbeddedArt.titleColor, 0, _local2);
            this.m_nameText.filters = EmbeddedArt.titleFilters;
            TextFieldUtil.formatSmallCaps(this.m_nameText.getTextField(), this.m_bigForm);
            _local1.appendAll(ASwingHelper.horizontalStrut(40), this.m_nameText, ASwingHelper.horizontalStrut(15));
            ASwingHelper.prepare(_local1);
            this.append(ASwingHelper.verticalStrut(-5));
            this.append(_local1);
            this.append(ASwingHelper.verticalStrut(-9));
            this.append(this.makePopulationPanel());
            var _local4:Sprite = new Sprite();
            _local4.graphics.beginFill(0xFF0000, 1);
            _local4.graphics.drawCircle(15, 15, 15);
            _local4.graphics.endFill();
            this.addChild(_local4);
            ASwingHelper.prepare(this);
        }
        protected function makePopulationPanel():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel();
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
            var _local3:JTextField = ASwingHelper.makeTextField((ZLoc.t("Main", "Population") + "  "), EmbeddedArt.TITLE_FONT, 13, EmbeddedArt.blueTextColor);
            LocaleHelper.localSetting.ASwingHelper_setEasyBorder(_local3, 0, 0, 9);
            _local2.appendAll(ASwingHelper.verticalStrut(5), _local3);
            var _local4:String = ((Utilities.formatNumber(Global.world.citySim.getScaledPopulation()) + "/") + Utilities.formatNumber(Global.world.citySim.getScaledPopulationCap()));
            this.m_popNumber = ASwingHelper.makeLabel(_local4, EmbeddedArt.TITLE_FONT, 13, EmbeddedArt.blueTextColor);
            _local1.appendAll(ASwingHelper.horizontalStrut(42), _local2, this.m_popNumber, ASwingHelper.horizontalStrut(15));
            ASwingHelper.prepare(_local1);
            return (_local1);
        }
        public function set cityName(_arg1:String):void{
            var _local2:String = _arg1;
            if (_local2 == ZLoc.t("Main", "NameSuffix")){
                _local2 = ((" " + ZLoc.t("Main", "NameSuffix")) + " ");
            };
            if (TextFieldUtil.isLowerCase(_local2)){
                _local2 = _local2.toUpperCase();
            };
            this.m_nameText.setText(_local2);
            TextFieldUtil.formatSmallCaps(this.m_nameText.getTextField(), this.m_bigForm);
            LocaleHelper.localSetting.TextField_adjust(this.m_nameText.getTextField(), {
                embedFonts:false,
                size:16,
                font:EmbeddedArt.SYSTEM_FONT
            });
            LocaleHelper.localSetting.matchFontAdjust_SIM_HEI(this.m_nameText, {
                topMargin:4,
                bottomMargin:3,
                textfield:this.m_nameText.getTextField(),
                size:19
            });
            ASwingHelper.prepare(this);
            ASwingHelper.prepare(this.parent);
        }
        protected function onMouseOver(_arg1:MouseEvent):void{
            if (!Global.ui.bNeighborActionsMenuOn){
                PopulationPopup.getInstance().show();
            };
            _arg1.stopPropagation();
        }
        protected function onMouseOut(_arg1:MouseEvent):void{
            PopulationPopup.getInstance().hide();
            _arg1.stopPropagation();
        }
        protected function onMouseUp(_arg1:MouseEvent):void{
            var _local2:PopulationDetailDialog;
            if (!Global.isVisiting()){
                _local2 = new PopulationDetailDialog();
                UI.displayPopup(_local2);
                _arg1.stopPropagation();
            };
        }
        public function onPopulationInit(_arg1:int, _arg2:int, _arg3:int):void{
        }
        public function onPopulationChanged(_arg1:int, _arg2:int, _arg3:int, _arg4:int):void{
            if (this.m_popNumber){
                this.m_popNumber.setText(((Utilities.formatNumber(Global.world.citySim.getScaledPopulation()) + "/") + Utilities.formatNumber(Global.world.citySim.getScaledPopulationCap())));
                ASwingHelper.prepare(this);
                ASwingHelper.prepare(this.parent);
            };
        }
        public function onPotentialPopulationChanged(_arg1:int, _arg2:int):void{
        }
        public function onPopulationCapChanged(_arg1:int):void{
            if (this.m_popNumber){
                this.m_popNumber.setText(((Utilities.formatNumber(Global.world.citySim.getScaledPopulation()) + "/") + Utilities.formatNumber(Global.world.citySim.getScaledPopulationCap())));
                ASwingHelper.prepare(this);
                ASwingHelper.prepare(this.parent);
            };
        }

    }
}//package Display.NeighborUI 
